package com.sharing.consumer;

import com.sharing.backgroundmodule.service.BackstageUserHobbyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.channels.Channel;

/**
 * @author MingTian
 * @version 1.0
 * @description TODO
 * @date 2023/7/7 18:13
 */
@Slf4j
@Component
public class RabbitmqConsumer {

    @Autowired
    private BackstageUserHobbyService backstageUserHobbyService;

    /**
     * 消费者，
     * 用于监听 QA 队列上的用户兴趣数量过界问题，
     * 并通过 LRU 算法删除掉多余的兴趣
     * @param userId
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = "QA")
    public void dealMessageQA(Integer userId, Channel channel) throws IOException {
        log.info("用户ID为：" + userId + " 的用户兴趣数量过界，需要进一步处理");
        backstageUserHobbyService.dealHobbyAmountOutOfBoundsLRU(userId);
    }
}
